package c.c.c.a.i;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import c.c.c.a.c.a.a;
import c.c.c.a.c.b;
import c.c.c.a.e.c;
import c.c.c.a.f;
import c.c.c.a.n;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import org.json.JSONObject;

/* compiled from: CrashFileCollector */
public final class e {
    public Context a;

    public e(Context context) {
        this.a = context;
    }

    public final f a(String str, JSONObject jSONObject) {
        if (jSONObject == null && TextUtils.isEmpty(str)) {
            return null;
        }
        if (str.startsWith("launch_")) {
            return f.LAUNCH;
        }
        if (str.startsWith("anr_")) {
            return f.ANR;
        }
        if (str.startsWith("java_")) {
            if (jSONObject.optInt("is_dart") == 1) {
                return f.DART;
            }
            if (jSONObject.optInt("isJava") == 1) {
                return f.JAVA;
            }
        }
        return null;
    }

    public void b(boolean z) {
        String str = "history_time";
        int i = 0;
        try {
            SharedPreferences sharedPreferences = this.a.getSharedPreferences("npth", 0);
            long j = sharedPreferences.getLong(str, -1);
            if (j < 0) {
                sharedPreferences.edit().putLong(str, System.currentTimeMillis()).apply();
            } else if (System.currentTimeMillis() - j > 86400000) {
                b.i.b.f.u(new File(b.i.b.f.G(this.a), "crash_history"));
                sharedPreferences.edit().putLong(str, System.currentTimeMillis()).apply();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (z) {
            Object[] objArr;
            File g = b.i.b.f.g(this.a);
            if (!g.exists()) {
                objArr = null;
            } else if (TextUtils.isEmpty(".npth")) {
                objArr = g.listFiles();
            } else {
                objArr = g.listFiles(new d(this));
            }
            if (objArr != null) {
                Arrays.sort(objArr, Collections.reverseOrder());
                while (i < objArr.length && i < 50) {
                    File file = objArr[i];
                    try {
                        if (b.a().d(file.getAbsolutePath())) {
                            b.i.b.f.u(file);
                        } else {
                            c F = b.i.b.f.F(file.getAbsolutePath());
                            if (F != null) {
                                JSONObject jSONObject = F.b;
                                if (jSONObject != null) {
                                    a(file.getName(), jSONObject);
                                    F.b.put("upload_scene", "launch_scan");
                                    if (c.c.c.a.o.b.a(F.a, jSONObject.toString(), F.c).a() && !b.i.b.f.u(file)) {
                                        b.a().c(a.a(file.getAbsolutePath()));
                                    }
                                }
                            }
                        }
                    } catch (Exception unused) {
                        Context context = n.a;
                        c cVar = n.d;
                    }
                    i++;
                }
            }
        }
    }
}
